package com.ztgf.commodity.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.ztgf.commodity.models.dto.CommoditySpecificationAttrDTO;
import com.ztgf.commodity.models.service.ICommoditySpecificationAttrService;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * author: chenyu.wang
 * date: 2020-06-03 14:43
 * Description:
 */
@RestController
@RequestMapping("/api/commoditySpecificationAttr")
@Slf4j
@Api(value = "CommoditySpecificationAttrApiController", tags = "商品规格属性表接口")
public class CommoditySpecificationAttrApiController {

    @DubboReference
    private ICommoditySpecificationAttrService specificationAttrService;

    @PostMapping(value = "/getBySpecificationId")
    @ApiOperation(value = "根据规格表id查询属性信息,用于发布商品界面", notes = "根据规格表id查询属性信息,用于发布商品界面")
    public Result getBySpecificationId(Long id) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        Wrapper<CommoditySpecificationAttrDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("status", 0)
                .eq("is_publish", 1)
                .eq("specification_id", id);
        List<CommoditySpecificationAttrDTO> list = specificationAttrService.selectList(wrapper);
        return new Result<>(list);
    }
}
